---
description: Hasura database source Health Check
title: 'Cloud: Source Health Check'
keywords:
  - hasura
  - cloud
  - enterprise
  - source health check
  - source health
sidebar_label: Source Health Check
sidebar_position: 20
sidebar_class_name: cloud-and-enterprise-icon
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import HeadingIcon from '@site/src/components/HeadingIcon';
import ProductBadge from '@site/src/components/ProductBadge';

# Source Health Check

<ProductBadge free ee self />

## Introduction

Hasura enables users to check the health of connected data sources via the Health Check API.
[API reference here](/api-reference/source-health.mdx).

## Configuring source Health Check

A Health Check configuration contains information that Hasura uses to determine the health state of a source. You can
set the time interval for when Hasura will re-perform the check on the source.

Currently, Hasura supports enabling Health Checks on Postgres and MS SQL Server databases. Support for other data
sources will be added soon.

Health Check configurations for Postgres and SQL Server sources are identical and are as follows.

<Tabs groupId="user-preference" className="api-tabs">
<TabItem value="console" label="Console">

Console support will be added soon.

</TabItem>
<TabItem value="cli" label="CLI">

You can add _health check_ for a source by adding the config to the `/metadata/databases/database.yaml` file:

```yaml {3-8}
- name: <db-name>
  kind: postgres
  health_check:
    test:
      sql: SELECT 1
    interval: 10
    retries: 3
    retry_interval: 5
    timeout: 5
  configuration:
    connection_info:
      database_url:
        from_env: <DATABASE_URL_ENV>
      pool_settings:
        idle_timeout: 180
        max_connections: 50
        retries: 1
```

Apply the Metadata by running:

```yaml
hasura metadata apply
```

</TabItem>
<TabItem value="api" label="API">

You can add/update _health check_ for a database using the
[pg_update_source](/api-reference/metadata-api/source.mdx#metadata-pg-update-source) Metadata API.

```http {7-18}
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
  {
    "type": "pg_update_source",
    "args": {
      "name": "default",
      "health_check": {
        "test": {
          "sql": "SELECT 1"
        },
        "interval": 100,
        "timeout": 2,
        "retries": 3,
        "retry_interval": 2
      }
    }
  }
}
```

</TabItem>
</Tabs>

## Reporting source Health Check

### API

Health Check reports of sources can be obtained through a `GET` request from the `/healthz/sources` API, on demand.
Learn more about the API [here](/api-reference/source-health.mdx).

### Logging

Hasura logs the Health Check status and other information via `health-check-log` type when enabled. Learn more about the
Health Checks logs [here](/deployment/logging.mdx#health-check-log-structure).
